<%-- 
    Document   : index
    Created on : Apr 27, 2012, 1:47:36 PM
    Author     : 
--%>

<%@page import="java.util.List"%>
<%@page import="cz.muni.fi.pb138.gscholarinfo.AuthorGraph"%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="cz.muni.fi.pb138.gscholarinfo.classes.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Google Scholar Info</title>
          <style type="text/css">
            body {
                font-family: Arial;
            }
            #content {
                text-align: center;
                margin-top: 50px;
            }
            .loading {
                margin: 20px;
                font-style:italic;
            }
            .error {
                color: red;
                margin: 20px;
            }
        </style>
    </head>
    <body>
        <div id="content">
        <h1><a href="MainServlet" style="text-decoration:none;"><span style="color:blue;">G</span><span style="color:red;">o</span><span style="color:yellow;">o</span><span style="color:blue;">g</span><span style="color:green;">l</span><span style="color:red;">e</span> Scholar Info</a></h1>
        <form method="post" action="MainServlet" id="nameForm" onsubmit="
            document.getElementById('loading').style.visibility='visible';
            if(document.getElementById('nores') != null) {
                document.getElementById('nores').style.visibility='hidden';}
            if(document.getElementById('fatal') != null) {
                document.getElementById('fatal').style.visibility='hidden';}">
                <label for="authorName">Insert name: <span style="font-size:12px;">
                    (for example <a href="#" onclick="
                        document.getElementById('authorName').value='Tomáš Pitner';
                        document.getElementById('nameForm').submit();
                        document.getElementById('loading').style.visibility='visible';
                        if(document.getElementById('nores')!=null){
                            document.getElementById('nores').style.visibility='hidden';}
                        if(document.getElementById('fatal')!=null){
                            document.getElementById('fatal').style.visibility='hidden';}
                            ">Tomáš Pitner</a>, <a href="#" onclick="
                        document.getElementById('authorName').value='Adam Rambousek';
                        document.getElementById('nameForm').submit();
                        document.getElementById('loading').style.visibility='visible';
                        if(document.getElementById('nores')!=null){
                            document.getElementById('nores').style.visibility='hidden';}
                        if(document.getElementById('fatal')!=null){
                            document.getElementById('fatal').style.visibility='hidden';}
                            ">Adam Rambousek</a> or <a href="#" onclick="
                        document.getElementById('authorName').value='Marek Grác';
                        document.getElementById('nameForm').submit();
                        document.getElementById('loading').style.visibility='visible';
                        if(document.getElementById('nores')!=null){
                            document.getElementById('nores').style.visibility='hidden';}
                        if(document.getElementById('fatal')!=null){
                            document.getElementById('fatal').style.visibility='hidden';}
                                  ">Marek Grác</a>)</span></label>
                <br />
                <br />
                <input name="authorName" id="authorName" type="text" value="<%=((request.getParameter("authorName") != null)?request.getParameter("authorName"):"")%>" />
                <input type="submit" value="Search" />
            </form>
            <div id="loading" class="loading" style="visibility:hidden;">
                Please be patient, collecting data...
            </div>
            <%
                Integer view = (request.getAttribute("view")!=null)?(Integer)request.getAttribute("view"):0;
                switch(view)
                {
                    case 1:
                        if(request.getAttribute("author")!=null)
                        {
                            Author author = (Author)request.getAttribute("author");
                            String graph = (request.getAttribute("graph")!=null)?(String)request.getAttribute("graph"):"";
                        %>
                        <h2><%=author.getName()%> (<a target="_blank" href="http://scholar.google.com/citations?user=<%=author.getGoogleId()%>">GS profile</a>)</h2>
                        <img src="http://scholar.google.com/citations?view_op=view_photo&user=<%=author.getGoogleId()%>" />
                        <br />
                        <strong>H-index: <%=author.getHIndex()%></strong>
                        <br />
                        <br />
                        <%=graph%>
                        <%
                        }
                        break;
                    case 2:
                        %>
                        <div class="error" id="nores">
                        Your search didn't find any results. Try again please.
                        </div>
                        <%
                        break;
                    case 3:
                        if(request.getAttribute("authors")!=null)
                        {
                            List<Author> authors = (List<Author>)request.getAttribute("authors");
                            %>
                            <h2>Search results:</h2>
                        <%
                            for(Author author:authors)
                            {
                            %>
                                <h3><%=author.getName()%> (<a target="_blank" href="http://scholar.google.com/citations?user=<%=author.getGoogleId()%>">GS profile</a>)</h3>
                                <img src="http://scholar.google.com/citations?view_op=view_photo&user=<%=author.getGoogleId()%>" />
                                <form action="MainServlet" method="post" onsubmit="document.getElementById('load_<%=author.getGoogleId()%>').style.visibility='visible';">
                                    <input type="hidden" name="authorID" value="<%=author.getGoogleId()%>" />
                                    <input type="hidden" name="authorName" value="<%=author.getName()%>" />
                                    <input type="submit" value="Calculate">
                                </form>
                                <div class="loading" id="load_<%=author.getGoogleId()%>" style="visibility:hidden;">
                                Please be patient, collecting data...
                                </div>
                            <%
                            }
                        }
                        break;                          
                    case 4:
                        %>
                        <div class="error" id="fatal">
                        Google Scholar unavailable. Try again later please.
                        </div>
                        <%
                        break;
                }
            
            %>
        </div>
    </body>
</html>
